package com.restaurant.application.indexes.consumptionlist.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;
import java.lang.Integer;
import java.lang.String;
import java.util.List;

public class ConsumptionConfig implements PickableBean {
    
    public static final String FN_ACCUMULATERATE = "accumulateRate";
    public static final String FN_DOSEARCHPATH = "doSearchPath";
    
    public static final List<String> FIELD_NAMES = Lists.newArrayList(
             FN_ACCUMULATERATE,
             FN_DOSEARCHPATH);
    
    private Integer accumulateRate;
    private String doSearchPath;
    
    public ConsumptionConfig(Integer accumulateRate, String doSearchPath) {
        setAccumulateRate(accumulateRate);
        setDoSearchPath(doSearchPath);
    }
    
    public ConsumptionConfig() {
    }
    
    public ConsumptionConfig duplicate() {
        ConsumptionConfig result = new ConsumptionConfig();
        result.accumulateRate = this.accumulateRate;
        result.doSearchPath = this.doSearchPath;
        return result;
    }
    
    @Override
    public String toString() {
        return Convert.toJson(this);
    }
    
    public Integer getAccumulateRate() {
        return accumulateRate;
    }
    
    public void  setAccumulateRate(Integer value) {
        this.accumulateRate = value;
    }
    
    public ConsumptionConfig withAccumulateRate(Integer value) {
        setAccumulateRate(value);
        return this;
    }
    
    public ConsumptionConfig withAccumulateRate(Integer value, Integer defaultValue) {
        setAccumulateRate(value == null ? defaultValue : value);
        return this;
    }
    
    public String getDoSearchPath() {
        return doSearchPath;
    }
    
    public void  setDoSearchPath(String value) {
        this.doSearchPath = value;
    }
    
    public ConsumptionConfig withDoSearchPath(String value) {
        setDoSearchPath(value);
        return this;
    }
    
    public ConsumptionConfig withDoSearchPath(String value, String defaultValue) {
        setDoSearchPath(value == null ? defaultValue : value);
        return this;
    }
    
    public Object getValueOf(String name) {
        switch(name) {
        case "accumulateRate": return getAccumulateRate();
        case "doSearchPath": return getDoSearchPath();
        }
        return null;
    }
    
    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }
    
    @Override
    public int hashCode() {
        return signature().hashCode();
    }
    
    @Override
    public boolean equals(Object o) {
        if(!(o instanceof ConsumptionConfig)) return false;
        return signature().equals(((ConsumptionConfig)o).signature());
    }
    
    public String signature() {
        throw new RuntimeException("Bean ConsumptionConfig has no signature defined, no hash code or equals possible.");
    }
}
